package com.lanxin.oa.qx.dao;

import com.lanxin.base.BaseDaoImpl;
import com.lanxin.bean.QxFunction;
import com.lanxin.bean.QxRole;
import com.lanxin.bean.ZzEmployee;
import com.lanxin.util.PageBean;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class QxroleDaoImpl extends BaseDaoImpl implements QxroleDao {
    @Override
    public PageBean<QxRole> selectRole(Integer page,Integer pageSize) {
        String hql="from QxRole";
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public QxRole selectByIdRole(Integer oid) {
        return (QxRole)selectByHQL("from QxRole qx left join fetch qx.employees left join fetch qx.functions where qx.oid="+oid);
    }

    @Override
    public PageBean<QxRole> pageRole(Integer page, Integer pageSize, String roleName) {
        String hql="select distinct role from QxRole role where 1=1";
        if(roleName!=null && !"".equals(roleName)){
            hql = hql+" and role.roleName like '%"+roleName+"%'";
        }
        return super.pageFenYE(hql,page,pageSize);
    }

    @Override
    public QxRole selectRoleUser(Integer oid) {
        return (QxRole)selectByHQL("from QxRole qx left join fetch qx.employees left join fetch qx.functions where qx.oid="+oid);
    }

    @Override
    public ZzEmployee selectEmp(String oid) {
        return (ZzEmployee)selectByHQL("from ZzEmployee emp where emp.oid='"+oid+"'");
    }

    @Override
    public List<QxFunction> functions() {
        return queryAll("select distinct qx from QxFunction qx left join fetch qx.functions where qx.parentid is null");
    }

    @Override
    public QxFunction selectFunction(String oid) {
        return (QxFunction)selectByHQL("from QxFunction qx where qx.oid='"+oid+"'");
    }

    @Override
    public List<ZzEmployee> myFunctions(Integer eid) {
        return queryAll("select distinct emp from ZzEmployee emp left join fetch emp.qxRoles q left join fetch q.functions where emp.oid="+eid);
    }

    @Override
    public List<QxRole> selectRole(Integer oid) {
        return queryAll("from QxRole qx left join fetch qx.employees left join fetch qx.functions where qx.oid="+oid);
    }

}
